package com.ht.controller;


import cn.hutool.json.JSONUtil;
import com.ht.data.Result;
import com.ht.dto.TbUserCollect;
import com.ht.dto.User;
import com.ht.service.ITbUserCollectService;
import com.ht.util.JwtUtil;
import io.jsonwebtoken.Claims;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 代齐园
 * @since 2022-05-28
 */
@RestController
@RequestMapping("/tbUserCollect")
@Api("关于用户收藏的信息")//Swagger2的注解
public class TbUserCollectController {
    @Autowired
    private ITbUserCollectService userCollectService;

    @GetMapping("/getHospital")
    //value为这个方法干什么用的
    @ApiOperation(value = "根据状态查询用户收藏的医院")
    //name是传的参是谁，value的意思是传的是什么，required是否必填，paramType传参的方式
    @ApiImplicitParam(name = "token",value = "用户token",required = true,paramType = "header")
    public Result getHospital(@RequestHeader("AuthToken")String token){
        Claims claims = new JwtUtil().parseJwt(token);
        User user = JSONUtil.toBean(claims.getSubject(), User.class);
        List<TbUserCollect> list = userCollectService.getHospital(user.getId());
        return Result.OK().setData(list);
    }

}
